﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MSTutHelloWebAPI.Models
{
    public class TextAnalyticsSingleton
    {
        private static TextAnalyticsSingleton _instance;
        private ObjectPool<TextAnalytics> ta;

        private TextAnalyticsSingleton()
        {
            ta = new ObjectPool<TextAnalytics>(() => new TextAnalytics());
        }

        public TextAnalytics GetTextAnalytics()
        {
            return ta.GetObject();
        }

        public void PutTextAnalytics(TextAnalytics item)
        {
            //item.Load(); // how to do this in async mode?
            ta.PutObject(item);
        }

        public static TextAnalyticsSingleton Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new TextAnalyticsSingleton();
                }
                return _instance;
            }
        }




        //private static TextAnalyticsSingleton _instance;
        //private static ObjectPool<TextAnalytics> ta;

        //private TextAnalyticsSingleton()
        //{
        //    ta = new ObjectPool<TextAnalytics>(() => new TextAnalytics());
        //}

        //public static TextAnalytics GetTextAnalytics()
        //{
        //    return ta.GetObject();
        //}

        //public void PutTextAnalytics(TextAnalytics item)
        //{
        //    //item.Load(); // how to do this in async mode?
        //    ta.PutObject(item);
        //}

        //public static TextAnalyticsSingleton Instance
        //{
        //    get
        //    {
        //        if (_instance == null)
        //        {
        //            _instance = new TextAnalyticsSingleton();
        //        }
        //        return _instance;
        //    }
        //}

    }
}